<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Fans;

class ProfileController extends Controller
{
    public function form()
    {
        return view('profile.form');
    }

    public function check(Request $request)
    {
        $this ->validate($request,[
            'name'  => 'required|between:1,190',
            'phone' => 'required|regex:/^1[34578][0-9]{9}$/',
        ]);

//        $user= new Fans();
//        $user->name=$request->name;
//        $user->phone=$request->phone;
//        $user->sex = '2';
//        $user->save();

        Fans::insertOnDuplicateKey([
            'name' => $request->name,
            'phone' => $request->phone,
            'sex' => 2,
        ]);

        return redirect('form/successed')->with(['url' => 'form']);

    }

    public function successed()
    {
        return view('successed')->with(['url' => 'form']);
    }
}
